package com.ybfenpan.controller.member.info;


import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.model.Member;
import com.ybfenpan.model.log.LogMoney;
import com.ybfenpan.service.MemberService;
import com.ybfenpan.service.NoticeService;
import com.ybfenpan.service.ParamWageService;
import com.ybfenpan.service.log.LogMoneyService;
import com.ybfenpan.service.log.LogMoneyTiService;
import com.ybfenpan.taglib.pagetag.Pagination;
import com.ybfenpan.utils.ContextUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by Administrator on 2016/3/25.
 */
@Controller
 
public class WelcomeInfoController extends BaseController {
    @Resource
    private NoticeService noticeService;
    @Resource
    private MemberService memberService;
    @Resource
    private ParamWageService paramWageService;

    @Resource
    private LogMoneyService logMoneyService;
   
    @RequestMapping("member/info/welcome.shtml")
    public String add(ModelMap model, HttpServletRequest request, HttpServletResponse response) throws Exception{
    	
		 
    	//代理商信息
    	Member member = ContextUtil.getMember();
    	member = memberService.getByKey(member.getId());
    	Member re=memberService.getByKey(member.getRecommendId());
    	request.setAttribute("member",member);
    	request.setAttribute("re",re);


        // 最新的公告列表
        Map<String, Object> formMap = new HashMap<String, Object>();
        formMap.put("where", " 1=1 order by commitDate desc limit 0,5");
        List<Map<String, Object>> noticeList = noticeService.queryForList("noticeForList", formMap);
        for (Map<String, Object> notice : noticeList) {
            if (notice.get("title").toString().length() > 50) {
                notice.put("title2", notice.get("title").toString().substring(0, 50) + "...");
            } else {
                notice.put("title2", notice.get("title").toString());
            }

        }
        request.setAttribute("noticeList", noticeList);

        // 最新公告
        Map notice = null;
        if (noticeList.size() > 0) {
            notice = noticeList.get(0);
        }
        request.setAttribute("notice", notice);

        Date now = new Date();
        request.setAttribute("now", now);


        Map<String, Object> logMap = new HashMap<String, Object>();
        logMap.put("isFa", "F");
        logMap.put("where", "1=1 and memberId="+member.getId()+"");
        List<LogMoney> listMoney = this.logMoneyService.queryForList("select", logMap);

        Double dongNum=0d;
        for (LogMoney logMoney:listMoney){
            dongNum=dongNum+logMoney.getDongNum();
        }

        request.setAttribute("dongNum", dongNum);
		return "member/info/welcome";
        
		
     
    }
     
}
